package com.example.springboot.mapper;


import com.example.springboot.entity.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Insert("INSERT INTO questions(post_id, question, options, correct_answer) VALUES(#{postId}, #{question}, #{options}, #{correctAnswer})")
    void insertQuestion(Question question);

    @Select("SELECT * FROM questions WHERE id = #{id}")
    Question getQuestionById(int id);

    @Select("SELECT * FROM questions WHERE post_id = #{postId}")
    List<Question> getQuestionsByPostId(int postId);

    @Update("UPDATE questions SET question = #{question}, options = #{options}, correct_answer = #{correctAnswer}, updated_at = CURRENT_TIMESTAMP WHERE id = #{id}")
    void updateQuestion(Question question);

    @Delete("DELETE FROM questions WHERE id = #{id}")
    void deleteQuestion(int id);
}